//必须是有顺序的排列，从两边向中间   low mid hei
let a = [1, 12, 6, 9, 4, 56, 8];
a.sort((a, b) => a - b);
function binary(a, value, low, hei) {
  let mid;
  if (low > hei) {
    return -1;
  }
  mid = Math.floor((low + hei) / 2); //这个是向下取整
  if (a[mid] === value) {
    return a[mid];
  }
  if (a[mid] > value) {
    return binary(a, value, low, mid);
  } else {
    return binary(a, value, mid, hei);
  }
}

console.log(binary(a, 6, 0, a.length));
